package com.ruoyi.web.disease.controller;

import java.io.IOException;
import java.util.Base64;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.departmentdisease.domain.vo.DepartmentDiseaseVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.disease.domain.Disease;
import com.ruoyi.disease.service.IDiseaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【病种】Controller
 * 
 * @author ruoyi
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/system/disease")
public class DiseaseController extends BaseController
{
    @Autowired
    private IDiseaseService diseaseService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Disease disease)
    {
        int i = diseaseService.selectDiseaseList1(disease);
        startPage();
        List<DepartmentDiseaseVO> departmentDiseaseVOS = diseaseService.selectDiseaseList(disease);
        TableDataInfo dataTable = getDataTable(departmentDiseaseVOS);
        dataTable.setTotal(i);
        return dataTable;
    }

    @GetMapping("/getList")
    public AjaxResult getList()
    {
        List<DepartmentDiseaseVO> departmentDiseaseVOS = diseaseService.selectDiseaseList(new Disease());
        return AjaxResult.success(departmentDiseaseVOS);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:disease:export')")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Disease disease)
//    {
//        List<Disease> list = diseaseService.selectDiseaseList(disease);
//        ExcelUtil<Disease> util = new ExcelUtil<Disease>(Disease.class);
//        util.exportExcel(response, list, "【请填写功能名称】数据");
//    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{diseaseId}")
    public AjaxResult getInfo(@PathVariable("diseaseId") Long diseaseId)
    {
        return success(diseaseService.selectDiseaseByDiseaseId(diseaseId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DepartmentDiseaseVO departmentDiseaseVO) {
        return toAjax(diseaseService.insertDisease(departmentDiseaseVO));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DepartmentDiseaseVO departmentDiseaseVO)
    {
        return toAjax(diseaseService.updateDisease(departmentDiseaseVO));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diseaseIds}")
    public AjaxResult remove(@PathVariable Long[] diseaseIds)
    {
        return toAjax(diseaseService.deleteDiseaseByDiseaseIds(diseaseIds));
    }

    @PostMapping("deleteDiseaseAll")
    public AjaxResult deleteDiseaseAll() {
        return AjaxResult.success(diseaseService.deleteDiseaseAll());
    }

    @PostMapping("addFile")
    public AjaxResult addFile(@RequestParam("file") MultipartFile file) throws IOException {
        return diseaseService.addFile(file);
    }
}
